package cn.com.xf.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.xf.dao.TbchinaareaDAO;
import cn.com.xf.dao.VChinaareaDAO;
import cn.com.xf.domain.Tbchinaarea;
import cn.com.xf.domain.VChinaarea;
import cn.com.xf.service.ChinaareaService;

@Service
public class ChinaareaServiceImpl implements ChinaareaService{

	@Autowired
	private  TbchinaareaDAO chinaareaDAO;

	
	@Override
	public List<Map<String, Object>> getProv() {
		List<Map<String,Object>> listMap = new ArrayList<Map<String,Object>>();
		List<Tbchinaarea> listTb  = chinaareaDAO.getProv();
		for(Tbchinaarea tbc : listTb){
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("provid", tbc.getAreaid());
			map.put("id", tbc.getAreaname());
			map.put("val", tbc.getAreaname());
			listMap.add(map);
		}
		return listMap;
	}

	@Override
	public List<Map<String, Object>> getCity(String prov) {
		List<Map<String, Object>> listMap = new ArrayList<Map<String,Object>>();
		List<Tbchinaarea> listTb  = chinaareaDAO.ProvAndCity(prov);
		for(Tbchinaarea tbc : listTb){
			Map<String,Object> map = new HashMap<String, Object>();
			map.put("cityid", tbc.getAreaid());
			map.put("id", tbc.getCity());
			map.put("val", tbc.getCity());
			listMap.add(map);
		}
		return listMap;
	}

	@Override
	public List<Map<String, Object>> getArea(String city) {
		List<Map<String, Object>> listMap = new ArrayList<Map<String,Object>>();
		List<Tbchinaarea> listTb  = chinaareaDAO.CityAndArea(city);
		for(Tbchinaarea tbc : listTb){
			Map<String,Object> map = new HashMap<String, Object>();
			map.put("id", tbc.getArea());
			map.put("val", tbc.getArea());
			listMap.add(map);
		}
		return listMap;
	}

	@Override
	public List<Tbchinaarea> CityAndArea(String city) {
		// TODO Auto-generated method stub
		return chinaareaDAO.CityAndArea(city);
	}

	@Override
	public List<Tbchinaarea> ProvAndCity(String prov) {
		// TODO Auto-generated method stub
		return chinaareaDAO.ProvAndCity(prov);
	}

	@Override
	public Tbchinaarea selectCityNameByAreaId(String areaId) {
		return chinaareaDAO.selectCityNameByAreaId(areaId);
	}


}
